/*
 * 删除分组
 */
package address;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.*;

/**
 *
 * @author Mavis
 */
public class DeletGroup extends JFrame {

    int H = 50;
    JPanel p = new JPanel();
    JLabel tip = new JLabel("请选择需要删除的分组：");
    JCheckBox jche = null;
    Font font = new Font("微软雅黑", Font.PLAIN, 16);
    ArrayList L = new ArrayList();

    DeletGroup(ArrayList contacts, ArrayList belongs) {
        setLayout(null);
        setBackground(Color.white);
        p.setLayout(null);
        p.setBackground(Color.white);
        JScrollPane jscp1 = new JScrollPane();
        jscp1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        p.setPreferredSize(new Dimension(400, 800));
        jscp1.setViewportView(p);
        jscp1.setBounds(0, 0, 450, 300);
        jscp1.setOpaque(false);
        jscp1.getViewport().setOpaque(false);
        add(jscp1);

        tip.setBounds(20, 10, 300, 30);
        tip.setFont(font);
        tip.setOpaque(false);
        p.add(tip);

        for (int i = 0; i < belongs.size(); i++) {
            String s = (String) belongs.get(i);
            jche = new JCheckBox(s);
            jche.setFont(font);
            jche.setBackground(Color.white);
            jche.setBounds(20, H, 300, 30);
            L.add(jche);
            p.add(jche);
            H += 40;
        }

        ImageIcon Icon1 = new ImageIcon("img/confirm.png");   
        JButton jbtkeep = new JButton(Icon1);
        jbtkeep.setBounds(30, 310, 100, 30);
        jbtkeep.setBorderPainted(false);
        jbtkeep.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                for (int i = 0; i < L.size(); i++) {
                    jche = (JCheckBox) L.get(i);
                    if (jche.isSelected()) {
                        String s = jche.getActionCommand();
                        belongs.remove(s);
                        for (int j = 0; j < contacts.size(); j++) {
                            People p = (People) contacts.get(j);
                            if (p.belongs.contains(s)) {
                                p.belongs.remove(s);

                            }
                        }
                    }
                }
                BeginPanel frame = new BeginPanel(contacts, belongs);
                frame.setSize(900, 700);
                frame.setTitle("欢迎使用通讯录管理系统");
                frame.setLocationRelativeTo(null);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
                dispose();
            }

        });
        add(jbtkeep);

        ImageIcon Icon2 = new ImageIcon("img/cancel_newPeople.png");    //保存联系信息
        JButton jbtcancel = new JButton(Icon2);
        jbtcancel.setBounds(250, 310, 100, 30);
        jbtcancel.setBorderPainted(false);
        jbtcancel.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                BeginPanel frame = new BeginPanel(contacts, belongs);
                frame.setSize(900, 700);
                frame.setTitle("欢迎使用通讯录管理系统");
                frame.setLocationRelativeTo(null);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
                dispose();
            }

        });
        add(jbtcancel);

    }

}
